package onlinebanking.client.gui;

import java.awt.Dimension;
import javax.swing.BorderFactory;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;

import onlinebanking.client.SimpleClient;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AnnouncementsPanel extends javax.swing.JPanel {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JLabel AnnouncementTitleLabel;
	private JTextPane announcements;
	private JLabel AnnouncementLabel;

	private ClientPanel parent;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new AnnouncementsPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public AnnouncementsPanel() {
		super();
		this.parent = null;
		initGUI();
	}
	
	public AnnouncementsPanel(ClientPanel parent) {
		super();
		this.parent = parent;
		initGUI();
		this.sendCommand();
	}
	
	private void initGUI() {
		try {
			this.setBackground(new java.awt.Color(0,255,174));
			this.setLayout(null);
			this.setBounds(0, 0, 515, 450);
			this.setPreferredSize(new java.awt.Dimension(590, 432));
			{
				AnnouncementTitleLabel = new JLabel();
				this.add(AnnouncementTitleLabel);
				AnnouncementTitleLabel.setText("ANNOUNCEMENTS");
				AnnouncementTitleLabel.setFont(new java.awt.Font("Arial Black",1,20));
				AnnouncementTitleLabel.setBounds(6, 6, 601, 44);
			}
			{
				AnnouncementLabel = new JLabel();
				this.add(AnnouncementLabel);
				AnnouncementLabel.setText("<html><p>Waiting for server response.</p></html>");
		
				AnnouncementLabel.setBounds(12, 56, 558, 312);
				AnnouncementLabel.setAlignmentY(0.0f);
				AnnouncementLabel.setHorizontalTextPosition(SwingConstants.CENTER);
				AnnouncementLabel.setVerticalAlignment(SwingConstants.TOP);
				AnnouncementLabel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void sendCommand(){
		this.parent.getSimpleClient().getAnnouncements();
	}
	
	public void appendAnnouncement(String announcement){
		this.AnnouncementLabel.setText(AnnouncementLabel.getText() + announcement);
	}
	
	public void clearAnnouncements(){
		this.AnnouncementLabel.setText("");
	}

}
